package cn.ryh.environmentvariable.entity;

import cn.ryh.environmentvariable.config.YmlPropertySourceFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 * 使用了ConfigurationProperties注解则可以不用单独使用@Value注解，只需变量名和配置中一一对应即可（根据驼峰规则）
 * @PropertySource 默认只能读取.properties文件，所以需要自己实现一个能够解析yml文件类，并指定解析工厂为我们自定义的解析类
 * factory = YmlPropertySourceFactory.class
 * @ClassName MyConfig
 * @Description 用于读取自定义配置文件信息
 * @Author RaoYH
 */
@Component
// @ConfigurationProperties(prefix = "project")
@PropertySource(value = "classpath:config.yml",factory = YmlPropertySourceFactory.class)
public class MyConfig {
    @Value("${project.version}")
    private String version;
    @Value("${project.name}")
    private String name;

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
